home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Chat & Communication / Digsby build 37 / digsby_setup.exe / lib / logextensions.pyo (.txt) < prev    next >
Python Compiled Bytecode  |  2008-10-13  |  5KB  |  168 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.5)
  3.  
  4. import logging
  5. LOGGING_ENABLED = True
  6. import types
  7. import sys
  8. import threading
  9. from traceback import print_exc
  10. from threading import currentThread
  11. _LogRecord = logging.LogRecord
  12.  
  13. class LogRecord(_LogRecord):
  14.     
  15.     def __init__(self, *a, **k):
  16.         _LogRecord.__init__(self, *a, **k)
  17.         self.threadCount = getattr(currentThread(), 'loopcount', 0)
  18.  
  19.     
  20.     def getMessage(self):
  21.         msg = self.msg
  22.         if type(msg) not in (unicode, str):
  23.             
  24.             try:
  25.                 msg = str(self.msg)
  26.             except UnicodeError:
  27.                 msg = repr(self.msg)
  28.             except:
  29.                 None<EXCEPTION MATCH>UnicodeError
  30.             
  31.  
  32.         None<EXCEPTION MATCH>UnicodeError
  33.         if self.args:
  34.             
  35.             try:
  36.                 msg = msg % self.args
  37.             except Exception:
  38.                 e = None
  39.                 print >>sys.stdout, self.filename, self.lineno, map(type, self.args), repr(msg), repr(self.args)
  40.                 return 'Error in log message (%r:%r): msg=%r, args=%r' % (self.filename, self.lineno, msg, self.args)
  41.             except:
  42.                 None<EXCEPTION MATCH>Exception
  43.             
  44.  
  45.         None<EXCEPTION MATCH>Exception
  46.         return msg
  47.  
  48.  
  49. logging.LogRecord = LogRecord
  50.  
  51. class StreamHandler(logging.Handler):
  52.     
  53.     def __init__(self, strm = None):
  54.         logging.Handler.__init__(self)
  55.         self._stream = strm
  56.         self.formatter = None
  57.         self.has_stream = True
  58.  
  59.     
  60.     def stream(self):
  61.         if self._stream is None and self.has_stream:
  62.             return sys.stderr
  63.         elif self.has_stream:
  64.             return self._stream
  65.         
  66.  
  67.     stream = property(stream)
  68.     
  69.     def flush(self):
  70.         
  71.         try:
  72.             self.stream.flush()
  73.         except:
  74.             if self._stream is not None:
  75.                 self._stream = None
  76.             else:
  77.                 self.has_stream = False
  78.  
  79.  
  80.     
  81.     def emit(self, record):
  82.         if not self.has_stream:
  83.             return None
  84.         
  85.         
  86.         try:
  87.             msg = self.format(record)
  88.             fs = '%s\n'
  89.             if not hasattr(types, 'UnicodeType'):
  90.                 self.stream.write(fs % msg)
  91.             else:
  92.                 
  93.                 try:
  94.                     self.stream.write(fs % msg)
  95.                 except UnicodeError:
  96.                     self.stream.write(fs % msg.encode('UTF-8'))
  97.                 except Exception:
  98.                     self.has_stream = False
  99.  
  100.             self.flush()
  101.         except (KeyboardInterrupt, SystemExit):
  102.             raise 
  103.         except:
  104.             self.handleError(record)
  105.  
  106.  
  107.  
  108. logging.StreamHandler = StreamHandler
  109. logging.FileHandler.__bases__ = (StreamHandler,) + logging.FileHandler.__bases__[1:]
  110.  
  111. def setup_sensitive_logs():
  112.     Logger = Logger
  113.     import logging
  114.     dev = getattr(sys, 'DEV', False)
  115.     full_log = getattr(getattr(sys, 'opts', None), 'full_log', False)
  116.     
  117.     nolog = lambda self, *a, **k: pass
  118.     for log_type in [
  119.         'critical',
  120.         'debug',
  121.         'error',
  122.         'exception',
  123.         'fatal',
  124.         'info',
  125.         'log',
  126.         'warn',
  127.         'warning']:
  128.         
  129.         def make_sensitive(name):
  130.             if dev or full_log:
  131.                 
  132.                 def sensitive(self, *a, **k):
  133.                     getattr(self, name)(*a, **k)
  134.  
  135.             else:
  136.                 sensitive = nolog
  137.             return sensitive
  138.  
  139.         func = make_sensitive(log_type)
  140.         setattr(Logger, log_type + '_s', func)
  141.     
  142.  
  143. setup_sensitive_logs()
  144. if not LOGGING_ENABLED:
  145.     
  146.     class NullRoot(object):
  147.         stream = None
  148.         setLevel = addHandler = info = (lambda : pass)
  149.  
  150.     
  151.     class NullLogger(object):
  152.         root = NullRoot()
  153.         handlers = []
  154.         debug = debug_s = info = info_s = warning = error = critical = (lambda : pass)
  155.  
  156.     _null_logger = NullLogger()
  157.     
  158.     class NullManager(object):
  159.         
  160.         def getLogger(self, name):
  161.             return _null_logger
  162.  
  163.  
  164.     _null_manager = NullManager()
  165.     NullLogger.manager = _null_manager
  166.     logging.Logger = NullLogger
  167.  
  168.